package com.top.art.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.top.art.bo.StudioBO;
import com.top.art.bo.StudioCourseBO;
import com.top.art.constants.Status;
import com.top.art.entity.Aggregation;
import com.top.art.entity.ExaminationPaper;
import com.top.art.mapper.ExaminationPaperMapper;
import com.top.art.service.IExaminationPaperService;
import com.top.art.vo.PaperScoreVO;
import com.top.art.vo.ResultList;
import com.top.art.vo.ScoreVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hjh
 * @since 2020 -10-05
 */
@Service
public class ExaminationPaperServiceImpl extends ServiceImpl<ExaminationPaperMapper, ExaminationPaper> implements IExaminationPaperService {

    /**
     * Aggregation list.
     *
     * @param wrapper the wrapper
     * @return the list
     */
    @Override
    public List<Aggregation> aggregation(Wrapper<ExaminationPaper> wrapper) {
        return baseMapper.aggregation(wrapper);
    }

    @Override
    public List<ScoreVO> queryScoreByCode(String admissionTicketCode) {
        return baseMapper.queryScoreByCode(admissionTicketCode);
    }

    @Override
    public IPage<ExaminationPaper> queryExaminationPaper(StudioBO bo) {
        return this.page(new Page<>(bo.getCurrent(),bo.getSize()),lambdaQuery()
                .eq(ExaminationPaper::getEnable, Status.VALID));
    }

    @Override
    public ResultList<PaperScoreVO> queryPaperDetail(StudioCourseBO bo) {
        ResultList<PaperScoreVO> ret = new ResultList<>();
        PageHelper.startPage(bo.getCurrent(), bo.getSize());
        List<PaperScoreVO> paperScoreVOS = baseMapper.queryPaperDetail(bo);
        ret.setList(paperScoreVOS);
        PageInfo pageInfo = new PageInfo(paperScoreVOS);
        ret.setTotal(pageInfo.getTotal());
        ret.setPageNum(bo.getCurrent());
        ret.setPageSize(bo.getSize());
        return ret;
    }
}
